package ocg.common.re;


import ocg.common.re.file.ReString;
import ocg.common.re.reports.ExtentTestNGReportBuilder;
import ocg.common.re.reports.TestReport;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenbo on 2017/10/25.
 */
public class Assertion {

    private static TestReport report;

    public static void set( TestReport report ){
        Assertion.report = report;
    }

    public static TestReport get(){
        return report;
    }

    /**
     * 布尔值判断
     * @param b
     * @param msg
     */
    public static boolean isTrue( boolean b , String msg) {
        try {
            org.testng.Assert.assertTrue ( b  , msg );
            report.pass ( msg );
            return true;
        } catch (  AssertionError error ){
            report.log_error( error );
            return false;
        }
    }

    public static boolean isFalse( boolean b , String msg) {
        try {
            org.testng.Assert.assertFalse ( b  , msg );
            report.pass ( msg );
            return true;
        } catch (  AssertionError error ){
            report.log_error ( error );
            return false;
        }
    }

    /**
     * 判断引用地址是否相同。
     * @param Expected
     * @param Actual
     * @param msg
     */
    public static boolean isSame( Object Expected ,Object Actual , String msg ) {
        try {
            org.testng.Assert.assertSame ( Expected  , Actual , msg );
            report.pass ( msg );
            return true;
        } catch (  AssertionError error ){
            report.log_error ( error );
            return false;
        }
    }

    public static boolean isNotSame(Object Expected ,Object Actual , String msg ) {
        try {
            org.testng.Assert.assertNotSame ( Expected , Actual , msg );
            report.pass ( msg );
            return true;
        } catch (  AssertionError error ){
            report.log_error ( error );
            return false;
        }
    }

    /**
     * 相等判断，必须是相同类型，支持数组，迭代器，set ,map ......
     * @param Expected
     * @param Actual
     * @param msg
     */
    public static boolean isEquals(Object Expected ,Object Actual , String msg ) {
        try {
            org.testng.Assert.assertEquals ( Expected , Actual , msg );
            report.pass ( msg );
            return true;
        } catch (  AssertionError error ){
            report.log_error ( error );
            return false;
        }
    }

    public static boolean isNotEquals(Object Expected ,Object Actual , String msg ) {
        try {
            org.testng.Assert.assertNotEquals ( Expected , Actual , msg );
            report.pass ( msg );
            return true;
        } catch (  AssertionError error ){
            report.log_error ( error );
            return false;
        }
    }

    /**
     * 判断是否为 null
     * @param o
     * @param msg
     */
    public static boolean isNull ( Object o , String msg ) {
        try {
            org.testng.Assert.assertNull ( o , msg );
            report.pass ( msg );
            return true;
        } catch ( AssertionError error ){
            report.log_error ( error );
            return false;
        }
    }

    /**
     * 判断不为空
     * @param o
     * @param msg
     * @return
     */
    public static boolean isNotNull ( Object o , String msg ) {
        try {
            org.testng.Assert.assertNotNull ( o , msg );
            report.pass ( msg );
            return true;
        } catch ( AssertionError error ){
            report.log_error ( error );
            return false;
        }
    }

    /**
     * 忽略顺序是否相等判断
     * @param Expected
     * @param Actual
     * @param msg
     * @return
     */
    public static boolean isEqualsNoOrder ( Object[] Expected ,Object[] Actual , String msg ) {
        try {
            org.testng.Assert.assertEqualsNoOrder ( Expected , Actual , msg );
            report.pass ( msg );
            return true;
        } catch ( AssertionError error ){
            report.log_error ( error );
            return false;
        }
    }

    /**
     * 检查字符串 Expected 是否包含字符串 Actual
     * @param Expected           期望值
     * @param Actual        实际值
     * @param msg       说明
     * @return
     */
    public static boolean isContains( String Expected , String Actual , String msg){

        if (ReString.isContains ( Expected , Actual )) {
            report.pass ( msg );
            return true;
        }else {
            report.log_error ( new AssertionError() );
            return false;
        }
    }

    /**
     * 检查字符串 Expected 是否包含字符串 Actual
     * 该检查忽略大小写
     * @param Expected           期望值
     * @param Actual        实际值
     * @param msg       说明
     * @return
     */
    public static boolean isIgnoreContains( String Expected , String Actual , String msg){

        if (ReString.isIgnoreContains ( Expected , Actual )) {
            report.pass ( msg );
            return true;
        }else {
            report.log_error ( new AssertionError() );
            return false;
        }
    }

}
